﻿@model TruckWatch.Cloud.Models.ViewModels.DriverModel
@{
    ViewBag.Title = "Detail for Driver " + Model.Driver.Name;
}
<br />
<fieldset>
    <legend>Driver</legend>
    <div class="display-field">
        <h1>@Model.Driver.Name</h1>
    </div>
    <div class="display-label">
        Truck Type</div>
    <div class="display-field">@Model.Driver.TruckType</div>
    <div class="display-label">
        Location (reported @Model.LastLocationReportTimeDisplay)</div>
    <div class="display-field">@Model.LastLocationLatLngString<br />
    @Model.LastLocationAddress</div>
    <div class="display-label">
        Status Message (reported @Model.LastMessageReportTime)</div>
    <div class="display-field">@Model.LastMessage</div>
    <br />
    @*<div class="display-label">
        Estimated Time To Arrival</div>
    <div class="display-field">@Model.EstimatedTimeToArrival</div>
    <div class="display-label">
        On Time Message</div>
    <div class="display-field">@Model.OnTimeMessage</div>*@
    <fieldset>
        <legend>
            <h3>
                Trips</h3>
        </legend>
        @Html.ActionLink("Add Trip", "AddDriverTrip", new { id = Model.Driver.Id, driverId = Model.Driver.Id })<br />
        <br />
        @(Html.Telerik().Grid(Model.AllTrips).Name("DriverTrips")
        .Columns(columns =>
        {
            columns.Bound(c => c.Origination.LocationName).Title("Origination").ReadOnly().Width(200);
            columns.Bound(c => c.Destination.LocationName).Title("Destination").ReadOnly().Width(200);
            columns.Bound(c => c.ScheduledDeparture).Title("Scheduled Departure").ReadOnly().Format("{0:yyyy-MM-dd HH:mm} GMT").Width(200);
            columns.Bound(c => c.ScheduledArrival).Title("Scheduled Arrival").ReadOnly().Format("{0:yyyy-MM-dd HH:mm} GMT").Width(200);
            columns.Bound(c => c.Id).Title("Delete").Width(200);
        })
        .CellAction(cell =>
        {
            if (cell.Column.Title == "Delete")
                cell.Text = Html.ActionLink("Delete", "DeleteDriverTrip", "Drivers", new { tripId = cell.DataItem.Id, driverId = cell.DataItem.DriverId }, null).ToString();
        })
        .DataKeys(x => x.Add(o => o.Id))
        .Pageable()
        .HtmlAttributes(new { style = "width:1060px" })
    )
    </fieldset>
    <h3>
        Location History</h3>
    @(Html.Telerik().Grid<TruckWatch.Cloud.Models.EF.TripPoint>().Name("LocationHistory")
        .BindTo(Model.TripPoints)
        .DataKeys(x => x.Add(o => o.Id))
        .Columns(x =>
        {
            x.Bound(c => c.Latitude).Title("Lat").ReadOnly().Format("{0:0.00}");
            x.Bound(c => c.Longitude).Title("Long").ReadOnly().Format("{0:0.00}");
            x.Bound(c => c.ArriveDate).Title("Date").Format("{0:yyyy-MM-dd HH:mm}").Format("{0:yyyy-MM-dd HH:mm} GMT"); ;
        })
        .Pageable()
    )
    <h3>
        Status History</h3>
    @(Html.Telerik().Grid<TruckWatch.Cloud.Models.EF.TripStatus>().Name("StatusHistory")
        .BindTo(Model.TripStatuses)
        .DataKeys(x => x.Add(o => o.Id))
        .Columns(x =>
        {
            x.Bound(c => c.TripId).Title("TripId").ReadOnly();
            x.Bound(c => c.StatusMessage).Title("Status Message").ReadOnly();
            x.Bound(c => c.StatusReason).Title("Status Reason");
            x.Bound(c => c.StatusDate).Title("Status Date").Format("{0:yyyy-MM-dd HH:mm} GMT");
        })
        .Pageable()
    )
    <h3>
        Received Messages</h3>
    @(Html.Telerik().Grid(Model.MessagesReceived).Name("MessagesReceived")
        .Columns(x =>
        {
            x.Bound(c => c.SenderDriver.Name);
            x.Bound(c => c.RecipientDriver.Name);
            x.Bound(c => c.MessageText);
            x.Bound(c => c.SendDate);
        })
        .Pageable()
    )
</fieldset>
<p>
    @*Html.ActionLink("Edit", "Edit", new { /* id=Model.PrimaryKey */ }) |
    @Html.ActionLink("Back to List", "Index")
    *@
</p>
